/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package szachy;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Robert
 */
public class Hetman extends Figura implements Serializable{
    private static final long serialVersionUID = 1L;
    public Hetman(char kolor, String nazwa, String rodzaj){
        this.kolor=kolor;
        iloscRuchu=8;
        this.nazwa=nazwa;
        this.rodzaj=rodzaj;
    }
 public boolean mozliwyRuch(int fromX, int fromY, int toX, int toY,IGra g){
 boolean answer = true;
 if((fromX==toX && fromY!=toY) || (fromX!=toX && fromY==toY)){//Czy Hetman robi ruch wieży
        Wieza z = new Wieza();
        answer = z.mozliwyRuch(fromX, fromY, toX, toY, g);
    }else if(Math.abs(fromX-toX)==Math.abs(fromY-toY)){//Czy Hetman robi ruch gońca
     Goniec z = new Goniec();
     answer = z.mozliwyRuch(fromX, fromY, toX, toY, g);
    }else
        answer = false;
 return answer;
 }
 public boolean mozliwoscBicia(int fromX, int fromY, int toX, int toY,IGra g){
     try {
            if (g.ZwrocFigure(toX, toY).CoTo().equals("krol")) {
                return false;
            }
        } catch (RemoteException ex) {
            Logger.getLogger(Pion.class.getName()).log(Level.SEVERE, null, ex);
        }
        if((fromX==toX && fromY!=toY) || (fromX!=toX && fromY==toY)){ //Czy Hetman robi ruch wieży
        Wieza z = new Wieza();
        return z.mozliwoscBicia(fromX, fromY, toX, toY, g);
        }else if(Math.abs(fromX-toX)==Math.abs(fromY-toY)){ //Czy Hetman robi ruch gońca
        Goniec z = new Goniec();
        return z.mozliwoscBicia(fromX, fromY, toX, toY, g);
        }else
        return false;
    }
}
